package com.neu.questionnaire_system.mapper;

import com.neu.questionnaire_system.entity.Cluster;
import com.neu.questionnaire_system.entity.Question;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xingle
 * @since 2022-11-07
 */
@Mapper
public interface QuestionMapper extends BaseMapper<Question> {
    //插入问题
    @Insert("insert into question values (#{qid},#{questionId},#{questionType},#{questionText})")
    int insertQuestion(@Param("qid") String qid, @Param("questionId") String questionId, @Param("questionType") String questionType, @Param("questionText") String questionText);

    //通过问卷id查询该问卷下的全部问题
    @Select("select * from question where qid = #{qid} order by count asc")
    List<Question> selectQuestionByQid(@Param("qid") String qid);

    //根据问题id来对问题内容和类型进行更新
    @Update("update question set questionType=#{questionType,jdbcType=VARCHAR},questionText=#{questionText,jdbcType=VARCHAR} where questionId=#{questionId,jdbcType=VARCHAR}")
    int updateQuestion(@Param("questionId") String questionId, @Param("questionType") String questionType, @Param("questionText") String questionText);

    //根据问题id进行删除问题
    @Delete("delete from question where questionId=#{questionId}")
    int deleteQuestion(@Param("questionId") String questionId);

    //查询全部题目（题库）
    @Select("select * from question")
    List<Question> showAllQuestion();

    //输入选项id并跳转到指定关联问题
    @Select("select * from question q left join choice c on c.toQuestion = q.questionId " +
            "where c.choiceId=#{choiceId}")
    List<Question> jumpToQuestion(@Param("choiceId") String choiceId);

    //created by libo 通过问卷的qid查询题目的主键map来批量查询选项
    @Select("select questionId from question where qid=#{qid} order by count asc")
    List<String> selectQuestionIdByQid(@Param("qid") String qid);

    //created by libo 2022-11-9根据问卷id进行删除问题
    @Delete("delete from question where qid=#{qid}")
    int deleteQuestionAll(@Param("qid") String qid);

    //查询单选题或多选题的作答人数
    List<Map<String,Object>> quesStatistics(String qid);

    //查询题目有效填写人数
    List<Map<String,Object>> queryEffectiveNum(String qid);

    List<Map<String,Object>> queryBlock(String qid);
}
